package com.fyw.magichome.http;

import com.fyw.magichome.Constants;

import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;


/**
 * 采用单例模式封装Retrofit
 * Created by FYW on 2017/7/26.
 */

public class RetrofitManager {
    private static RetrofitManager mRetrofitManager;
    private Retrofit retrofit;

    private RetrofitManager() {
        initRetrofit();
    }

    public static synchronized RetrofitManager getInstance() {
        if (mRetrofitManager == null)
            mRetrofitManager = new RetrofitManager();
        return mRetrofitManager;
    }

    private void initRetrofit() {
        retrofit = new Retrofit.Builder()
                .baseUrl(Constants.BASE_URL)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
    }

    public <T> T createReq(Class<T> reqServer) {
        return retrofit.create(reqServer);
    }

}
